package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;
import com.opensymphony.oscache.util.StringUtil;

public class ImagesListRequest extends Request {
	
	private static final long serialVersionUID = 520939211521317493L;
	
	private HttpRequestInfo requestInfo;
	private int userId;
	private String userName;
	private String direct;
	private String ip;
	private String refResource;
	
	@Override
	public void parse(HttpServletRequest request) {
		requestInfo = new HttpRequestInfo(request);
		userName = requestInfo.getParameter(ApiUrlParamEnum.accountName.getParamName());
		userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), -1);
		direct = requestInfo.getParameter(ApiUrlParamEnum.dirName.getParamName());
		ip = requestInfo.getUserIp();
		refResource = requestInfo.getParameter(ApiUrlParamEnum.refResource.getParamName());
		
		if(StringUtil.isEmpty(direct)) {
			throw new RequestIllegalException("文件目录不能为空");
		}
		
		if(direct.length() <=2 || direct.charAt(0) != '/' || direct.charAt(direct.length()-1) != '/') {
			throw new RequestIllegalException("文件目录格式错误不能为空");
		}
		
		if(StringUtil.isEmpty(userName) || userId < 0) {
			throw new RequestIllegalException("用户名和用户ID不能为空");
		}
	}
	
	public HttpRequestInfo getRequestInfo() {
		return requestInfo;
	}

	public void setRequestInfo(HttpRequestInfo requestInfo) {
		this.requestInfo = requestInfo;
	}
	
	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public String getDirect() {
		return direct;
	}

	public void setDirect(String direct) {
		this.direct = direct;
	}

	public String getIp() {
		return this.ip;
	}
	
	public void setIp(String ip) {
		this.ip = ip;
	}
	
	public String getRefResource() {
		return this.refResource;
	}
	
	public void setRefResource(String refResource) {
		this.refResource = refResource;
	}
}
